using UnityEngine;

public class SpawnPoint : MonoBehaviour
{
	private static SpawnPoint instance;

	private static GameObject parentObject;

	public static bool isLevelStart;

	private static void Init()
	{
		if ((bool)instance)
		{
			return;
		}
		parentObject = GameObject.Find("SpawnPoint");
		if (parentObject != null)
		{
			instance = parentObject.GetComponent<SpawnPoint>();
		}
		else
		{
			parentObject = new GameObject("SpawnPoint");
			instance = parentObject.AddComponent<SpawnPoint>();
		}
		if (!Application.isEditor && Economy.hasInstance)
		{
			return;
		}
		GameObject gameObject = GameObject.Find("DEBUG Spawn");
		if (gameObject != null)
		{
			parentObject.transform.position = gameObject.transform.position;
			parentObject.transform.rotation = gameObject.transform.rotation;
			return;
		}
		GameObject gameObject2 = GameObject.Find("Level Start");
		if (gameObject2 == null)
		{
			gameObject2 = GameObject.Find("Level Start Old");
		}
		if (gameObject2 != null)
		{
			Debug.Log("init spawn point to Level Start");
			isLevelStart = true;
			parentObject.transform.position = gameObject2.transform.TransformPoint(Vector3.up * 0.5415f);
			if (gameObject2.name == "Level Start Old")
			{
				parentObject.transform.position = gameObject2.transform.TransformPoint(Vector3.up * 0.75f);
			}
			parentObject.transform.rotation = gameObject2.transform.rotation;
		}
	}

	public static SpawnPoint GetInstance()
	{
		Init();
		return instance;
	}

	public static GameObject GetGameObject()
	{
		Init();
		return parentObject;
	}

	public static void SetPosition(Vector3 pos, bool isAtLevelStart = false)
	{
		Init();
		parentObject.transform.position = pos;
		isLevelStart = isAtLevelStart;
	}

	public static void SetRotation(Quaternion rot)
	{
		Init();
		parentObject.transform.rotation = rot;
	}
}
